import { isDevEnv } from "@/config/env";
import { removeEmpty } from ".";
import { removeHttp, addHttp, axios } from "@/assets/js/axios";
const instance = axios.create({
  baseURL: isDevEnv
    ? import.meta.env.VITE_PROXY_PATH
    : import.meta.env.VITE_PROXY_TARGET,
  timeout: 1000 * 60 * 10,
  headers: {
    "Content-Type": "application/json"
  }
});
instance.interceptors.request.use(
  config => {
    config.params = removeEmpty(config.params);
    if (!isFormData(config.data)) {
      addHttp(config);
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
instance.interceptors.response.use(
  response => {
    removeHttp(response.config);
    return response.data;
  },
  error => {
    removeHttp(error.config);
    return Promise.reject(error);
  }
);
instance.defaults.headers.common["Content-Type"] = "application/json";
export default instance;
